package com.zrwl.poscloud.base.enums;

import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

public class EMessageModel {
    /***
     * 平台类型 (platform_type)-字典类型【message_platform_type】
     */
    public static final int PLATFORM_TYPE_SMS = 1;//短信
    public static final int PLATFORM_TYPE_WX = 2;//微信
    public static final int PLATFORM_TYPE_EMAIL = 3;//邮件
    public static final int PLATFORM_TYPE_STATION = 4;//站内信
    public static final int PLATFORM_TYPE_SYS = 5;//系统信息

    @Contract(pure = true)
    public static @Nullable String getByName(int type) {
        switch (type) {
            case PLATFORM_TYPE_SMS:
                return "短信";
            case PLATFORM_TYPE_WX:
                return "微信";
            case PLATFORM_TYPE_EMAIL:
                return "邮件";
            case PLATFORM_TYPE_STATION:
                return "站内信";
            case PLATFORM_TYPE_SYS:
                return "系统信息";
        }
        return null;
    }
    @Contract(pure = true)
    public static @Nullable String getLabelName(int type) {
        switch (type) {
            case PLATFORM_TYPE_SMS:
                return "SMS";
            case PLATFORM_TYPE_WX:
                return "WX";
            case PLATFORM_TYPE_EMAIL:
                return "EMAIL";
            case PLATFORM_TYPE_STATION:
                return "STATION";
            case PLATFORM_TYPE_SYS:
                return "SYS";
        }
        return null;
    }
    @Contract(pure = true)
    public static @Nullable Integer getLabelValue(String name) {
        switch (name) {
            case "SMS":
                return PLATFORM_TYPE_SMS;
            case "WX":
                return PLATFORM_TYPE_WX;
            case "EMAIL":
                return PLATFORM_TYPE_EMAIL;
            case "STATION":
                return PLATFORM_TYPE_STATION;
            case "SYS":
                return PLATFORM_TYPE_SYS;
        }
        return null;
    }
    @Contract(pure = true)
    public static @Nullable String getModelType(int type, MessageModelType modelType) {
        switch (type) {
            case PLATFORM_TYPE_SMS:
                return "SMS_"+modelType.getType();
            case PLATFORM_TYPE_WX:
                return "WX_"+modelType.getType();
            case PLATFORM_TYPE_EMAIL:
                return "EMAIL_"+modelType.getType();
            case PLATFORM_TYPE_STATION:
                return "STATION_"+modelType.getType();
            case PLATFORM_TYPE_SYS:
                return "SYS_"+modelType.getType();
        }
        return null;
    }
    @Contract(pure = true)
    public static MessageModelType getModelType(String modelType) {
        if(!modelType.contains("_")){
            return null;
        }
        if (!modelType.split("_")[1].matches("\\d+")) {//字符串不是数字
            return null;
        }
        return MessageModelType.getByValue(Objects.requireNonNull(getLabelValue(modelType.split("_")[0])),Integer.parseInt(modelType.split("_")[1]));
    }
}
